package com.aisino.api.model;

import org.springframework.util.StringUtils;

import java.util.List;

public class DrugInfoRequest {
    private String appId;
    private String timestamp;
    private String reqId;
    private String uscc;
    //private List<DrugInfoData> data;
    private String data;
    private String sign;

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(String timestamp) {
        this.timestamp = timestamp;
    }

    public String getReqId() {
        return reqId;
    }

    public void setReqId(String reqId) {
        this.reqId = reqId;
    }

    public String getUscc() {
        return uscc;
    }

    public void setUscc(String uscc) {
        this.uscc = uscc;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public String getSign() {
        return sign;
    }

    public void setSign(String sign) {
        this.sign = sign;
    }

    public static class DrugInfoData {
        private String id;
        private String yppzwh;
        private String ypssxkcyrmc;
        private String ypscqymc;
        private String yptymc;
        private String ypspmc;
        private String bzgg;
        private String zjgg;
        private String jx;
        private String ypzcfl;
        private String cfybs;
        private String ybmlyp;
        private String gchjkyp;
        private String ypfl;
        private Integer ypyxq;
        private String ypyxqdw;

        private String yptxm;//	是	药品条形码
        private String  ypbsm;//	是	药品追溯码前7位
        private String gjybbm;//	是	国家医保编码
        private String ypcf;//	是	药品成份
        private String yyjj;//	是	用药禁忌
        private String tsrq;//	是	特殊人群
        private String gnzz;//	是	功能主治
        private String yfyl;//	是	用法用量
        private String ypxz;//	是	药品性状
        private String blfs;//	是	不良反应
        private String cctj;//	是	储藏条件
        private String zysx;//	是	注意事项
        private String xhzy;//	是	相互作用
        private String yptp;//	是	药品图片，多个图片地址用英文逗号隔开（http或https开头的互联网访问地址）
        
        /**
         * 验证必填字段
         * @param index 数据索引（用于错误消息）
         * @return ValidationResult 验证结果，如果验证通过则返回null
         */
        public ValidationResult validate(int index) {
            if (!StringUtils.hasText(this.id)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的id不能为空");
            }

            if (!StringUtils.hasText(this.yppzwh)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的yppzwh不能为空id="+this.id);
            }

            if (!StringUtils.hasText(this.ypssxkcyrmc)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的ypssxkcyrmc不能为空id="+this.id);
            }

            if (!StringUtils.hasText(this.ypscqymc)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的ypscqymc不能为空id="+this.id);
            }

            if (!StringUtils.hasText(this.yptymc)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的yptymc不能为空id="+this.id);
            }

//            if (!StringUtils.hasText(this.ypspmc)) {
//                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
//                        "第" + index + "条数据中的ypspmc不能为空");
//            }

            if (!StringUtils.hasText(this.bzgg)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的bzgg不能为空id="+this.id);
            }

            if (!StringUtils.hasText(this.zjgg)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的zjgg不能为空id="+this.id);
            }

            if (!StringUtils.hasText(this.jx)) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的jx不能为空id="+this.id);
            }
//            String[] validJxValues = {
//                    "01", "0101", "0102", "0103", "0104", "0105", "0106", "0107", "0108", "0109",
//                    "0110", "0111", "0112", "0113", "0114", "0199", "02", "0201", "0202", "0203",
//                    "0299", "03", "0301", "0302", "0303", "0304", "0305", "0399", "04", "0401",
//                    "0402", "0403", "0404", "0405", "0406", "0499", "05", "0501", "0502", "0503",
//                    "0504", "0505", "0506", "0507", "0508", "0509", "0599", "06", "0601", "0602",
//                    "0603", "0604", "0605", "0606", "0607", "0608", "0609", "0610", "0699", "07",
//                    "0701", "0702", "0703", "0799", "08", "0801", "0802", "0803", "0804", "0805",
//                    "0806", "0807", "0808", "0809", "0810", "0899", "09", "0901", "0902", "0999",
//                    "10", "11", "1101", "1102", "1103", "1104", "1105", "1199", "12", "1201",
//                    "1202", "1203", "1299", "13", "1301", "1302", "1399", "14", "15", "16",
//                    "17", "18", "19", "20", "21", "22", "2201", "2202", "2299", "23", "24",
//                    "25", "26", "2601", "2602", "2603", "2604", "2605", "2606", "2607", "2608",
//                    "2609", "2699", "27", "28", "29", "30", "31", "32", "33", "34", "35",
//                    "36", "37", "3701", "3702", "3703", "3799", "38", "99"
//            };
//
//            boolean isValid = false;
//            for (String validValue : validJxValues) {
//                if (validValue.equals(this.jx)) {
//                    isValid = true;
//                    break;
//                }
//            }
//
//            if (!isValid) {
//                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
//                        "第" + index + "条数据中的jx值不正确，请参考剂型代码表");
//            }
            // 验证药品注册分类（如果提供了值）
            if (StringUtils.hasText(this.ypzcfl) &&
                    !("1".equals(this.ypzcfl) || "2".equals(this.ypzcfl) || "3".equals(this.ypzcfl))) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的ypzcfl值不正确，应为1(中药)、2(化学药)或3(生物制品)id="+this.id);
            }
            // 验证处方药标识（如果提供了值）
            if (StringUtils.hasText(this.cfybs) &&
                    !("1".equals(this.cfybs) || "2".equals(this.cfybs) || "3".equals(this.cfybs))) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的cfybs值不正确，应为1(处方药)、2(OTC)或3(其它)id="+this.id);
            }

            //1=是 2=否
            // 验证是否医保名录药品（如果提供了值）
            if (!StringUtils.hasText(this.ybmlyp) &&
                    !("1".equals(this.ybmlyp) || "2".equals(this.ybmlyp))) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的ybmlyp值不正确，应为1(是)或2(否)id="+this.id);
            }

            //20251113 刘振洲添加如果是医保药品,必须传医保编码
            if ("1".equals(this.ybmlyp)) {
                if (!StringUtils.hasText(this.gjybbm)) {
                    return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                            "第" + index + "条数据中的gjybbm值不正确，id="+this.id);
                }
            }
            // 验证国产或进口药品标识（如果提供了值）
            if (StringUtils.hasText(this.gchjkyp) &&
                    !("1".equals(this.gchjkyp) || "2".equals(this.gchjkyp))) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的gchjkyp值不正确，应为1(国产)或2(进口)id="+this.id);
            }

            // 验证药品有效期单位（如果提供了值）
            if (StringUtils.hasText(this.ypyxqdw) &&
                    !("D".equals(this.ypyxqdw) || "M".equals(this.ypyxqdw) || "Y".equals(this.ypyxqdw))) {
                return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                        "第" + index + "条数据中的ypyxqdw值不正确，应为D(天)、M(月)或Y(年)id="+this.id);
            }
            // 验证药品分类（如果提供了值）
//            if (StringUtils.hasText(this.ypfl)) {
//                String[] validYpflValues = {
//                        "01", "06", "04", "05", "03", "07", "08", "25", "02", "12", "13", "09", "19",
//                        "16", "17", "21", "22", "23", "10", "14", "26", "15", "24", "18", "11", "20"
//                };
//
//                boolean isValid = false;
//                for (String validValue : validYpflValues) {
//                    if (validValue.equals(this.ypfl)) {
//                        isValid = true;
//                        break;
//                    }
//                }
//
//                if (!isValid) {
//                    return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
//                            "第" + index + "条数据中的ypfl值不正确，请参考药品分类字典");
//                }
//            }
            //如果传了药品条形码，则必须是13位
//            if (StringUtils.hasText(this.yptxm)) {
//                if ( !this.yptxm.matches("\\d{13}")) {
//                    return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
//                            "第" + index + "条数据中的yptxm值不正确，请输入13位药品条形码");
//                }
//            }
            //如果传了ypbsm则必须是7位数字
            if (StringUtils.hasText(this.ypbsm)) {
                if ( !this.ypbsm.matches("\\d{7}")) {
                    return new ValidationResult(ResultCode.PARAM_ERROR.getCode(),
                            "第" + index + "条数据中的ypbsm值不正确，请输入7位数字的药品标识码id="+this.id);
                }
            }
            return null; // 验证通过
        }
        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getYppzwh() {
            return yppzwh;
        }

        public void setYppzwh(String yppzwh) {
            this.yppzwh = yppzwh;
        }

        public String getYpssxkcyrmc() {
            return ypssxkcyrmc;
        }

        public void setYpssxkcyrmc(String ypssxkcyrmc) {
            this.ypssxkcyrmc = ypssxkcyrmc;
        }

        public String getYpscqymc() {
            return ypscqymc;
        }

        public void setYpscqymc(String ypscqymc) {
            this.ypscqymc = ypscqymc;
        }

        public String getYptymc() {
            return yptymc;
        }

        public void setYptymc(String yptymc) {
            this.yptymc = yptymc;
        }

        public String getYpspmc() {
            return ypspmc;
        }

        public void setYpspmc(String ypspmc) {
            this.ypspmc = ypspmc;
        }

        public String getBzgg() {
            return bzgg;
        }

        public void setBzgg(String bzgg) {
            this.bzgg = bzgg;
        }

        public String getZjgg() {
            return zjgg;
        }

        public void setZjgg(String zjgg) {
            this.zjgg = zjgg;
        }

        public String getJx() {
            return jx;
        }

        public void setJx(String jx) {
            this.jx = jx;
        }

        public String getYpzcfl() {
            return ypzcfl;
        }

        public void setYpzcfl(String ypzcfl) {
            this.ypzcfl = ypzcfl;
        }

        public String getCfybs() {
            return cfybs;
        }

        public void setCfybs(String cfybs) {
            this.cfybs = cfybs;
        }

        public String getYbmlyp() {
            return ybmlyp;
        }

        public void setYbmlyp(String ybmlyp) {
            this.ybmlyp = ybmlyp;
        }

        public String getGchjkyp() {
            return gchjkyp;
        }

        public void setGchjkyp(String gchjkyp) {
            this.gchjkyp = gchjkyp;
        }

        public String getYpfl() {
            return ypfl;
        }

        public void setYpfl(String ypfl) {
            this.ypfl = ypfl;
        }

        public Integer getYpyxq() {
            return ypyxq;
        }

        public void setYpyxq(Integer ypyxq) {
            this.ypyxq = ypyxq;
        }

        public String getYpyxqdw() {
            return ypyxqdw;
        }

        public void setYpyxqdw(String ypyxqdw) {
            this.ypyxqdw = ypyxqdw;
        }

        public String getYptxm() {
            return yptxm;
        }

        public void setYptxm(String yptxm) {
            this.yptxm = yptxm;
        }

        public String getYpbsm() {
            return ypbsm;
        }

        public void setYpbsm(String ypbsm) {
            this.ypbsm = ypbsm;
        }

        public String getGjybbm() {
            return gjybbm;
        }

        public void setGjybbm(String gjybbm) {
            this.gjybbm = gjybbm;
        }

        public String getYpcf() {
            return ypcf;
        }

        public void setYpcf(String ypcf) {
            this.ypcf = ypcf;
        }

        public String getYyjj() {
            return yyjj;
        }

        public void setYyjj(String yyjj) {
            this.yyjj = yyjj;
        }

        public String getTsrq() {
            return tsrq;
        }

        public void setTsrq(String tsrq) {
            this.tsrq = tsrq;
        }

        public String getGnzz() {
            return gnzz;
        }

        public void setGnzz(String gnzz) {
            this.gnzz = gnzz;
        }

        public String getYfyl() {
            return yfyl;
        }

        public void setYfyl(String yfyl) {
            this.yfyl = yfyl;
        }

        public String getYpxz() {
            return ypxz;
        }

        public void setYpxz(String ypxz) {
            this.ypxz = ypxz;
        }

        public String getBlfs() {
            return blfs;
        }

        public void setBlfs(String blfs) {
            this.blfs = blfs;
        }

        public String getCctj() {
            return cctj;
        }

        public void setCctj(String cctj) {
            this.cctj = cctj;
        }

        public String getZysx() {
            return zysx;
        }

        public void setZysx(String zysx) {
            this.zysx = zysx;
        }

        public String getXhzy() {
            return xhzy;
        }

        public void setXhzy(String xhzy) {
            this.xhzy = xhzy;
        }

        public String getYptp() {
            return yptp;
        }

        public void setYptp(String yptp) {
            this.yptp = yptp;
        }
    }
}